package com.jyc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jyc.entity.web.Goupiaoxinxi;
import com.jyc.service.WebService;
import com.jyc.util.DateUtils;
import com.jyc.util.HttpResult;
import com.jyc.vo.shop.ItemChartVO;
import com.jyc.vo.web.GoupiaoxinxiVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/web")
@CrossOrigin("*")
public class WebController {
    @Autowired
    private WebService webService;

    /**
     * 购票信息
     * @return
     */
    @RequestMapping("/toList")
    public HttpResult toList(@RequestParam("pageIndex") Integer pageIndex,@RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Goupiaoxinxi> goupiaoxinxis = webService.getItemList();
        List<GoupiaoxinxiVO> goupiaoxinxiVOList = new ArrayList<>();
        for (Goupiaoxinxi goupiaoxinxi : goupiaoxinxis) {
            GoupiaoxinxiVO goupiaoxinxiVO = new GoupiaoxinxiVO();
            BeanUtils.copyProperties(goupiaoxinxi,goupiaoxinxiVO);
            goupiaoxinxiVO.setAddtime(DateUtils.convertDateToString(goupiaoxinxi.getAddtime()));
            goupiaoxinxiVO.setGoupiaoriqi(DateUtils.convertDateToString(goupiaoxinxi.getGoupiaoriqi()));
            goupiaoxinxiVOList.add(goupiaoxinxiVO);
        }
        PageInfo<Goupiaoxinxi> pageInfo = new PageInfo<Goupiaoxinxi>(goupiaoxinxis, pageSize);
        return HttpResult.ok(pageInfo);
    }

    /**
     * 景点受欢迎比例
     * @return
     */
    @RequestMapping("/showPie")
    public HttpResult showPie() {
        List<GoupiaoxinxiVO> zucheChartVOS = webService.showPie();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同景点的收入金额
     * @return
     */
    @RequestMapping("/showPillar")
    public HttpResult showPillar() {
        List<GoupiaoxinxiVO> zucheChartVOS = webService.showPillar();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同购票日期的售票数
     * @return
     */
    @RequestMapping("/showLine")
    public HttpResult showLine() {
        List<GoupiaoxinxiVO> zucheChartVOS = webService.showLine();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同时间的不同景点的总购票数
     * @return
    */
    @RequestMapping("/show3DByNum")
    public HttpResult show3DByNum() {
        Set<List> chartVOS = webService.show3DByNum();
        return HttpResult.ok(chartVOS);
    }

    /**
     * 不同时间的不同景点的总购票金额
     * @return
     */
    @RequestMapping("/show3DByPrice")
    public HttpResult show3DByPrice() {
        Set<List> chartVOS = webService.show3DByPrice();
        return HttpResult.ok(chartVOS);
    }
}
